package com.example.photoview;

import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.image.Image;

import java.util.ArrayList;
import java.util.Optional;

/**
 * 显示图片具体属性
 */
public class AtrAction {
    private HomeController homeController=(HomeController) ControllerUtil.controllers.get(HomeController.class.getSimpleName());
    ArrayList<ImageModel> sourceList = SelectionModel.getImageModels();//存放图片本身的List
    public AtrAction(ImageBox imageBox){
        Image image = new Image(imageBox.getImageModel().getImageFile().toURI().toString());
   if(sourceList.isEmpty()||sourceList.size()==1){
       Alert dialog=new Alert(Alert.AlertType.CONFIRMATION);
       dialog.setTitle("属性");
       dialog.setHeaderText(imageBox.getImageModel().getImageName());
       dialog.setContentText("尺寸:"+image.getWidth()+"*"+image.getHeight()+"\n"+
               "类型:"+imageBox.getImageModel().getImageType()+"\n"+
               "修改时间:"+imageBox.getImageModel().getFormDate()+"\n"+
               "大小:"+imageBox.getImageModel().getFormLength()+"\n"+
               "位置:"+imageBox.getImageModel().getFilePath()+"\n");
       Optional<ButtonType> result=dialog.showAndWait();
       if(result.get()==ButtonType.OK){
           dialog.close();
       }else{
           dialog.close();
       }

  }else{
       Alert dialog=new Alert(Alert.AlertType.CONFIRMATION);
       dialog.setTitle("属性");
       dialog.setHeaderText("多图片属性");
       double totalSize=0;
       for(ImageModel im:sourceList){
           totalSize=im.getFileLength()+totalSize;
       }
       dialog.setContentText("图片数量:"+sourceList.size()+"\n"+
                             "图片大小:"+totalSize+"\n"+
                             "图片位置:"+imageBox.getImageModel().getFilePath());
       Optional<ButtonType> result=dialog.showAndWait();
       if(result.get()==ButtonType.OK){
           dialog.close();
       }else{
           dialog.close();
       }
   }
    }
}
